/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gr.jcash.dmp;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author gelson
 */
@Entity
@Table(name = "usuario", catalog = "jcash", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Usuario.buscarTodos", query = "SELECT u FROM Usuario u"),
    @NamedQuery(name = "Usuario.buscarPorId", query = "SELECT u FROM Usuario u WHERE u.idUsu = :p0"),
    @NamedQuery(name = "Usuario.buscarPorLogin", query = "SELECT u FROM Usuario u WHERE u.usuLogin = :p0"),
    @NamedQuery(name = "Usuario.buscarPorNome", query = "SELECT u FROM Usuario u WHERE u.usuNome = :p0"),
    @NamedQuery(name = "Usuario.count", query = "SELECT COUNT(u.idUsu) FROM Usuario u")})
public class Usuario extends EntidadeBase implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_usu", nullable = false)
    private Long idUsu;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "usu_login", nullable = false, length = 10, unique = true)
    private String usuLogin;
    @Size(max = 100)
    @Column(name = "usu_nome", length = 100)
    private String usuNome;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 128)
    @Column(name = "usu_senha", nullable = false, length = 128)
    private String usuSenha;
    @JoinTable(name = "usuario_grupo", joinColumns = {
        @JoinColumn(name = "id_usu", referencedColumnName = "id_usu", nullable = false)},
        inverseJoinColumns = {@JoinColumn(name = "id_grp", referencedColumnName = "id_grp", nullable = false)})
    @ManyToMany(fetch = FetchType.EAGER)
    private Collection<Grupo> grupoCollection;

    public Usuario() {
    }

    public Long getIdUsu() {
        return idUsu;
    }

    public void setIdUsu(Long idUsu) {
        this.idUsu = idUsu;
    }

    public String getUsuLogin() {
        return usuLogin;
    }

    public void setUsuLogin(String usuLogin) {
        this.usuLogin = usuLogin;
    }

    public String getUsuNome() {
        return usuNome;
    }

    public void setUsuNome(String usuNome) {
        this.usuNome = usuNome;
    }

    public String getUsuSenha() {
        return usuSenha;
    }

    public void setUsuSenha(String usuSenha) {
        this.usuSenha = usuSenha;
    }

    public Collection<Grupo> getGrupoCollection() {
        return grupoCollection;
    }

    public void setGrupoCollection(Collection<Grupo> grupoCollection) {
        this.grupoCollection = grupoCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUsu != null ? idUsu.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usuario)) {
            return false;
        }
        Usuario other = (Usuario) object;
        if ((this.idUsu == null && other.idUsu != null) || (this.idUsu != null && !this.idUsu.equals(other.idUsu))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return usuNome;
    }

    @Override
    public void setId(Long id) {
        this.idUsu = id;
    }

    @Override
    public Long getId() {
        return idUsu;
    }
}
